class Admin::ShopCategoryBrandsController < AdminController
  before_action :set_shop_category

  def index
    @shop_category_brands = @shop_category.shop_category_brands.order("created_at ASC").page(params[:page]).per(params[:per])
  end

  def new
    @shop_category_brand = ShopCategoryBrand.new
  end

  def create
    @shop_category_brand = @shop_category.shop_category_brands.build shop_category_brand_params
    if @shop_category_brand.save
      redirect_to admin_shop_category_shop_category_brands_path(@shop_category), notice: "保存成功！"
    else
      redirect_to admin_shop_category_shop_category_brands_path(@shop_category), notice: "保存失败！"
    end
  end
  
  def destroy
    @shop_category_brand = ShopCategoryBrand.find params[:id]
    if @shop_category_brand.destroy
      redirect_to admin_shop_category_shop_category_brands_path(@shop_category), notice: "删除成功."
    else
      redirect_to admin_shop_category_shop_category_brands_path(@shop_category), notice: "删除失败."
    end
  end

  private

  def set_shop_category
    @shop_category = ShopCategory.find params[:shop_category_id]
  end
  

  def shop_category_brand_params
    params.require(:shop_category_brand).permit(:brand_id)
  end
end
